(function($, im, doc) {
	//显示聊天信息页
	$.plusReady(function() {
		document.getElementById("red_packet").addEventListener('tap', function() {
			//plus.webview.close('red_packet','none');
			mui.openWindow({
				url: '../../pages/coin/red_packet.html',
				id: 'red_packet',
				extras: {
					roomId: im.roomId,
					roomType : im.roomType
				},
				createNew:false
			});
		});
		//点击红包
		/*
		document.getElementById("red_packet").addEventListener('tap', function() {
			if(im.roomType == 1 || im.roomType == 2) //个人红包
			{
				var postUrl = apiurl + "wallet/getWallets";
				var postdata = {
					from_id: im.uid,
					to_id: (im.roomType == 1 ? im.roomId : 0)
				};
				//im.playsendSound('hb');
				$.post(postUrl, postdata, function(res) {
					if(res.status == 1) {
						var f = res.data.from;
						var t = res.data.to;
						var url = "";
						var id = "";
						if(im.roomType == 1) {
							id = "pages/chat/red_packet";
							url = "../../pages/chat/red_packet.html?fromtype=3&id=" + f['id'] + "&name=" + f['name'] + "&pubkey=" + f.pubkey + "&type=" + f.type + "&tokens=" + f.tokens + "&isdefault=1&user_id=" + im.uid + "&to=" + t.address + "&roomid=" + im.roomId;
						} else {
							id = "pages/chat/red_packet_room";
							url = "../../pages/chat/red_packet_room.html?fromtype=4&id=" + f['id'] + "&name=" + f['name'] + "&pubkey=" + f.pubkey + "&type=" + f.type + "&tokens=" + f.tokens + "&isdefault=1&user_id=" + im.uid + "&roomid=" + im.roomId;
						}

						console.log(url);
						mui.openWindow({
							url: url,
							id: id,
							extras: {
								roomId: im.roomId
							}
						});
					} else {
						mui.alert(res.msg);
					}
				});
			} else {
				mui.alert("功能未开通");
			}
		});
		*/
		window.addEventListener('PAY_HONGBAO_SUCC', function(event) {
			var detailid = event.detail.detailid;
			var tradeid = event.detail.tradeid;
			var fromtype = event.detail.fromtype;
			var remark = event.detail.remark;
			var money = event.detail.money;
			im.sendMsg({
				sender: 'self',
				type: 'hongbao',
				content: detailid,
				extras: {
					tradeid: tradeid,
					remark: remark,
					money: money
				}
			});
			im.playsendSound('hb');
			im.closeFooterBox();

		});

		window.addEventListener('PAY_ROOM_HONGBAO_SUCC', function(event) {
			var detailid = event.detail.detailid;
			var tradeid = event.detail.tradeid;
			var remark = event.detail.remark;
			var money = event.detail.money;
			var type = 'hongbao';
			im.sendMsg({
				sender: 'self',
				type: type,
				content: tradeid,
				extras: {
					remark: remark,
					money: money
				}
			});
			im.playsendSound('hb');
			im.closeFooterBox();
		});

		window.addEventListener('RECV_HONBAO_SUCC', function(event) {
			im.sendMsg({
				sender: 'self',
				type: 'recvhongbao',
				content: im.user_name
			});
		});

		window.addEventListener('RECV_ROOM_HONBAO_SUCC', function(event) {
			im.sendMsg({
				sender: 'self',
				type: 'recvhongbao',
				content: im.user_name
			});
		});
	});
}(mui, im, document));